package com.mozq.ssm.web;

import com.mozq.ssm.config.shiro.MyRealm;
import com.mozq.ssm.config.shiro.MyToken;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @RequestMapping("/login")
    public String login(String storeId, String telephone){
        MyToken token = new MyToken();
        token.setStoreId(storeId);
        token.setTelephone(telephone);
        Subject subject = SecurityUtils.getSubject();
        try {
            subject.login(token);
        } catch (AuthenticationException e) {
            e.printStackTrace();
            return "fail";
        }
        Object user = SecurityUtils.getSubject().getPrincipal();
        System.out.println(user);
        return "ok";
    }
}
